package chapter3.test02;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.sql.DataSource;

public class DeleteAllStatement implements StatementStrategy {

	DataSource dataSource;
	Connection c ;
	PreparedStatement ps ;
	public void setDataSource(DataSource dataSource){
		this.dataSource = dataSource;
	}
	@Override
	public PreparedStatement makePreparedStatement(Connection c)
			throws SQLException {
		// TODO Auto-generated method stub
		PreparedStatement ps = c.prepareStatement("delete from users");
		return ps;
	}
	
	public void deleteAll() throws SQLException{
		
		
		try{
			c = dataSource.getConnection();
			StatementStrategy strategy = new DeleteAllStatement();
			strategy.makePreparedStatement(c);
			
		}catch(Exception e){
			
		}finally{
			
			if(ps != null){
				try{
					ps.close();
				}catch(SQLException e){
					
				}
			}
			if(c != null){
				try{
						c.close();
				}catch(SQLException e){
					
				}
			}	
		}
		
	}
	

}
